<template>
  <panel>
    <div class="container">
      <x-row>
        <x-col :span="11" class="state-box-parent" :style="{height: chartHeight}">
          <x-row class="state-box">
            <div class="title"><span>保利天悦设备监控中心</span></div>
            <div class="addr"><span>广州市海珠区阅江中路南侧</span></div>
          </x-row>
          <x-row class="state-box1">
            <x-col :span="8">
              <text-box
                titlePlace="bottom"
                size="large"
                title="监控设备数"
                :value="56">
              </text-box>
            </x-col>
            <x-col :span="8">
              <text-box
                titlePlace="bottom"
                size="large"
                title="监控区域"
                :value="19">
              </text-box>
            </x-col>
            <x-col :span="8">
              <text-box
                titlePlace="bottom"
                size="large"
                title="今日异常"
                type="danger"
                :value="3">
              </text-box>
            </x-col>
          </x-row>
          <x-row class="state-box2">
            <div class="state">
              <span class="lalbel">在线设备:</span>
              <span class="value">53</span>
            </div>
            <div class="state">
              <span class="lalbel">服务故障率:</span>
              <span class="value">3%</span>
            </div>
            <div class="state">
              <span class="lalbel">2017.2.24 星期五</span>
            </div>
          </x-row>
        </x-col>
        <x-col :span="13" class="failure-statistic">
          <div class="total" v-animated-number="12"></div>
          <pie :width="chartWidth" :height="chartHeight" :options="chartOptions"></pie>
        </x-col>
      </x-row>
    </div>
  </panel>
</template>

<script>
export default {
  name: 'Statistic',

  data () {
    return {
      chartWidth: '100px',
      chartHeight: '100px',
      chartOptions: null
    }
  },

  mounted () {
    setTimeout(this.initialize, 0)
  },

  methods: {
    initialize () {
      this.chartWidth = `${(this.$el.clientWidth - 35) / 24 * 13}px`
      this.chartHeight = `${this.$el.clientHeight}px`
      this.chartOptions = {
        title: {
          text: '服务异常事件统计',
          x: 'center',
          bottom: 10,
          textStyle: {
            color: '#999',
            fontSize: 12,
            fontWeight: 'normal'
          }
        },
        series: [{
          radius: ['40%', '60%'],
          center: ['50%', '45%'],
          data: [
            {value: 25, name: '门禁故障'},
            {value: 16, name: '给排水异常'},
            {value: 14, name: '水泵故障'},
            {value: 6, name: '道闸故障'},
            {value: 11, name: '其他信息'}
          ]
        }]
      }
    }
  }
}
</script>

<style lang="stylus" scoped>
@import '../../../../assets/stylus/common'

.container {
  padding-left: 35px;
}

.state-box-parent
  position relative
  min-height 200px
.state-box
  height: 40%
  display: flex;
  flex-direction: column;
  justify-content: center;
  .title
    font-size 24px
    font-weight 400
  .addr
    font-size 12px
    color #6B6B6B
.state-box1
  height: 33%
  display: flex;
  flex-direction: row;
  justify-content: center;
.state-box2
  position absolute
  bottom 0
  left 0px
  height 40px
  width 100%
  font-size 10px
  color #6B6B6B
  border-top 1px dashed
  padding-top 10px
  .state
    display inline-block
    margin-right 10px
    .value
      color #fff

.failure-statistic {
  position: relative;

  .total {
    absolute: left top 45%;
    margin-top: -20px;
    size: 100% 40px;
    font-size: 30px;
    line-height: 40px;
    text-align: center;
  }
}
</style>
